#ifndef ABSTRACT_SCHEDULER_H
#define ABSTRACT_SCHEDULER_H

#include "../task/abstract_task.h"
#include "../policy/abstract_policy.h"
#include <memory>
#include <vector>

namespace scheduler
{
class AbstractScheduler;
using AbstractSchedulerConstPtr = std::shared_ptr<AbstractScheduler>;

class AbstractScheduler
{
public:
    explicit AbstractScheduler(const std::string &name);

    virtual ~AbstractScheduler();
    /**
     * @brief:  追加单个task
     * @author: sherlock_lht
     */
    virtual bool appendTask(const task::AbstractTaskConstPtr &task);

    /**
     * @brief:  追加task组合而成得任务调度链
     * @author: sherlock_lht
     */
    virtual bool appendScheduler(const AbstractSchedulerConstPtr &scheduler);

    /**
     * @brief:  设置task
     * @author: sherlock_lht
     */
    virtual bool setTask(const task::AbstractTaskConstPtr &task);

    /**
     * @brief:  设置task组
     * @author: sherlock_lht
     */
    virtual bool setScheduler(const AbstractSchedulerConstPtr &scheduler);

    /**
     * @brief:  获取该调度器得调度策略
     * @author: sherlock_lht
     */
    virtual policy::AbstractPolicyConstPtr getTaskPolicy();

    /**
     * @brief:  设置上下文管理器
     * @author: sherlock_lht
     */
    virtual void setContext(task::Context *context);

    /**
     * @brief:  转字符串
     * @author: sherlock_lht
     */
    virtual std::string toString();

    /**
     * @brief:  获取调度器名称
     * @author: sherlock_lht
     */
    std::string getName() const;

    /**
     * @brief:  运行调度器
     * @author: sherlock_lht
     */
    void run();

    /**
     * @brief:  暂停调度
     * @author: sherlock_lht
     */
    void pause();

    /**
     * @brief:  恢复已经暂停的调度
     * @author: sherlock_lht
     */
    void resume();

    /**
     * @brief:  取消调度
     * @author: sherlock_lht
     */
    void cancel();

    void initialize();

    void taskEventNotify(task::TaskEventType task_event_type);

    void setTaskEventNotify(task::TaskEventNotify event_notify);

protected:
    std::string scheduler_name_;
    policy::AbstractPolicyConstPtr schedule_policy_;
    std::vector<AbstractSchedulerConstPtr> scheduler_vec_;
    task::TaskEventNotify event_notify_;
};
}

#endif //ABSTRACT_SCHEDULER_H
